using System;
using System.Data;
using System.Diagnostics;     // Debug
using System.Configuration;
using System.Collections;
using System.IO;              // Stream
using System.Web; 
using System.Web.Security;
using System.Web.SessionState;

namespace DbService
{
   public class Global : System.Web.HttpApplication
   {
      public static int uberTeller = 0;

      public enum RespondeCodes
      {
         TRANSACTION_UNKOWN = 0,
         TRANSACTION_SUCCES = 100,
         TRANSACTION_FAILED = -1,
         TRANSACTION_SYSOVERLOAD = 200
      }

      protected void Application_Start(object sender, EventArgs e)
      {
         // Create a logfile
         StreamWriter logFile = File.CreateText("C:/Inetpub/wwwroot/DBService/debug.log");
         Debug.Listeners.Add(new TextWriterTraceListener(logFile));
      }

      protected void Application_End(object sender, EventArgs e)
      {

      }

      static public int NextId()
      {
         if (Global.uberTeller > Int32.MaxValue - 1)
            Global.uberTeller = 0;
         return uberTeller++;
      }

      static public string GetConnectionString()
      {
         // Return the connection string from the root Web.config
         ConnectionStringSettings settings;
         settings = ConfigurationManager.ConnectionStrings["DatabaseConnection"];
         if (settings != null)
         {
            return settings.ConnectionString;
         }
         return "";
      }

      static public void WriteDebugLine(string message)
      {
         // Write message to logfile
         Debug.WriteLine(message);
         Debug.Flush();
      }
   }
}